package org.road0329.dlt698.axdr;

import org.road0329.dlt698.ReverseByteArrayInputStream;
import org.road0329.dlt698.ReverseByteArrayOutputStream;
import org.road0329.dlt698.asn1.axdr.AxdrEnum;
import org.road0329.dlt698.asn1.axdr.AxdrType;

public class Proxy_Response extends AxdrType {
    private byte[] dataCode = null;
    private Choice choice = Choice._ERR_NONE_SELECTED;
    private ProxyGetResponseList proxyGetResponseList = null;
    private ProxyGetResponseRecord proxyGetResponseRecord = null;
    private ProxySetResponseList proxySetResponseList = null;
    private ProxySetThenGetResponseList proxySetThenGetResponseList = null;
    private ProxyActionResponseList proxyActionResponseList = null;
    private ProxyActionThenGetResponseList proxyActionThenGetResponseList = null;
    private ProxyTransCommandResponse proxyTransCommandResponse = null;

    public Proxy_Response() {
    }

    public byte[] getDataCode() {
        return dataCode;
    }

    public Choice getChoice() {
        return choice;
    }

    public ProxyGetResponseList getProxyGetResponseList() {
        return proxyGetResponseList;
    }

    public ProxyGetResponseRecord getProxyGetResponseRecord() {
        return proxyGetResponseRecord;
    }

    public ProxySetResponseList getProxySetResponseList() {
        return proxySetResponseList;
    }

    public ProxySetThenGetResponseList getProxySetThenGetResponseList() {
        return proxySetThenGetResponseList;
    }

    public ProxyActionResponseList getProxyActionResponseList() {
        return proxyActionResponseList;
    }

    public ProxyActionThenGetResponseList getProxyActionThenGetResponseList() {
        return proxyActionThenGetResponseList;
    }

    public ProxyTransCommandResponse getProxyTransCommandResponse() {
        return proxyTransCommandResponse;
    }

    public void setDataCode(byte[] dataCode) {
        this.dataCode = dataCode;
    }

    public void setProxyGetResponseList(ProxyGetResponseList proxyGetResponseList) {
        this.resetChoices();
        this.choice = Choice.PROXY_SET_RESPONSE_LIST;
        this.proxyGetResponseList = proxyGetResponseList;
    }

    public void setProxyGetResponseRecord(ProxyGetResponseRecord proxyGetResponseRecord) {
        this.resetChoices();
        this.choice = Choice.PROXY_GET_RESPONSE_RECORD;
        this.proxyGetResponseRecord = proxyGetResponseRecord;
    }

    public void setProxySetResponseList(ProxySetResponseList proxySetResponseList) {
        this.resetChoices();
        this.choice = Choice.PROXY_SET_RESPONSE_LIST;
        this.proxySetResponseList = proxySetResponseList;
    }

    public void setProxySetThenGetResponseList(ProxySetThenGetResponseList proxySetThenGetResponseList) {
        this.resetChoices();
        this.choice = Choice.PROXY_SET_THEN_GET_RESPONSE_LIST;
        this.proxySetThenGetResponseList = proxySetThenGetResponseList;
    }

    public void setProxyActionResponseList(ProxyActionResponseList proxyActionResponseList) {
        this.resetChoices();
        this.choice = Choice.PROXY_ACTION_RESPONSE_LIST;
        this.proxyActionResponseList = proxyActionResponseList;
    }

    public void setProxyActionThenGetResponseList(ProxyActionThenGetResponseList proxyActionThenGetResponseList) {
        this.resetChoices();
        this.choice = Choice.PROXY_ACTION_THEN_GET_RESPONSE_LIST;
        this.proxyActionThenGetResponseList = proxyActionThenGetResponseList;
    }

    public void setProxyTransCommandResponse(ProxyTransCommandResponse proxyTransCommandResponse) {
        this.resetChoices();
        this.choice = Choice.PROXY_TRANS_COMMAND_RESPONSE;
        this.proxyTransCommandResponse = proxyTransCommandResponse;
    }

    public int decode(ReverseByteArrayInputStream input) throws Exception {
        int codeLength = 0;
        AxdrEnum choosen = new AxdrEnum();
        codeLength += choosen.decode(input);
        this.resetChoices();
        this.choice = Choice.getEnumByValue((int)choosen.getValue());
        if (this.choice == Choice.PROXY_GET_RESPONSE_LIST) {
            this.proxyGetResponseList = new ProxyGetResponseList();
            codeLength += this.proxyGetResponseList.decode(input);
            return codeLength;
        } else if (this.choice == Choice.PROXY_GET_RESPONSE_RECORD) {
            this.proxyGetResponseRecord = new ProxyGetResponseRecord();
            codeLength += this.proxyGetResponseRecord.decode(input);
            return codeLength;
        } else if (this.choice == Choice.PROXY_SET_RESPONSE_LIST) {
            this.proxySetResponseList = new ProxySetResponseList();
            codeLength += this.proxySetResponseList.decode(input);
            return codeLength;
        } else if (this.choice == Choice.PROXY_SET_THEN_GET_RESPONSE_LIST) {
            this.proxySetThenGetResponseList = new ProxySetThenGetResponseList();
            codeLength += this.proxySetThenGetResponseList.decode(input);
            return codeLength;
        } else if (this.choice == Choice.PROXY_ACTION_RESPONSE_LIST) {
            this.proxyActionResponseList = new ProxyActionResponseList();
            codeLength += this.proxyActionResponseList.decode(input);
            return codeLength;
        } else if (this.choice == Choice.PROXY_ACTION_THEN_GET_RESPONSE_LIST) {
            this.proxyActionThenGetResponseList = new ProxyActionThenGetResponseList();
            codeLength += this.proxyActionThenGetResponseList.decode(input);
            return codeLength;
        } else if (this.choice == Choice.PROXY_TRANS_COMMAND_RESPONSE) {
            this.proxyTransCommandResponse = new ProxyTransCommandResponse();
            codeLength += this.proxyTransCommandResponse.decode(input);
            return codeLength;
        }
        throw new Exception("Error decoding AxdrChoice: Identifier matched to no item.");
    }

    public int encode(ReverseByteArrayOutputStream output) throws Exception {
        if (this.dataCode != null) {
            for (int i = this.dataCode.length - 1; i >= 0; i--) {
                output.write(this.dataCode[i]);
            }
            return this.dataCode.length;
        }
        if (this.choice == Choice._ERR_NONE_SELECTED) {
            throw new Exception("Error encoding AxdrChoice: No item in choice was selected.");
        }
        int codeLength = 0;
        if (this.choice == Choice.PROXY_TRANS_COMMAND_RESPONSE) {
            codeLength += this.proxyTransCommandResponse.encode(output);
            AxdrEnum c = new AxdrEnum();
            c.setMinMaxVal(7);
            codeLength += c.encode(output);
            return codeLength;
        } else if (this.choice == Choice.PROXY_ACTION_THEN_GET_RESPONSE_LIST) {
            codeLength += this.proxyActionThenGetResponseList.encode(output);
            AxdrEnum c = new AxdrEnum();
            c.setMinMaxVal(6);
            codeLength += c.encode(output);
            return codeLength;
        } else if (this.choice == Choice.PROXY_ACTION_RESPONSE_LIST) {
            codeLength += this.proxyActionResponseList.encode(output);
            AxdrEnum c = new AxdrEnum();
            c.setMinMaxVal(5);
            codeLength += c.encode(output);
            return codeLength;
        } else if (this.choice == Choice.PROXY_SET_THEN_GET_RESPONSE_LIST) {
            codeLength += this.proxySetThenGetResponseList.encode(output);
            AxdrEnum c = new AxdrEnum();
            c.setMinMaxVal(4);
            codeLength += c.encode(output);
            return codeLength;
        } else if (this.choice == Choice.PROXY_SET_RESPONSE_LIST) {
            codeLength += this.proxySetResponseList.encode(output);
            AxdrEnum c = new AxdrEnum();
            c.setMinMaxVal(3);
            codeLength += c.encode(output);
            return codeLength;
        } else if (this.choice == Choice.PROXY_GET_RESPONSE_RECORD) {
            codeLength += this.proxyGetResponseRecord.encode(output);
            AxdrEnum c = new AxdrEnum();
            c.setMinMaxVal(2);
            codeLength += c.encode(output);
            return codeLength;
        } else if (this.choice == Choice.PROXY_GET_RESPONSE_LIST) {
            codeLength += this.proxyGetResponseList.encode(output);
            AxdrEnum c = new AxdrEnum();
            c.setMinMaxVal(1);
            codeLength += c.encode(output);
            return codeLength;
        }
        throw new Exception("Error encoding AxdrChoice: No item in choice was encoded.");
    }

    public void encodeAndSave(int encodingSizeGuess) throws Exception {
        ReverseByteArrayOutputStream revOStream = new ReverseByteArrayOutputStream();
        revOStream.setBufSize(encodingSizeGuess);
        this.encode(revOStream);
        this.dataCode = revOStream.getArray();
    }

    public Choice getChoiceIndex() {
        return this.choice;
    }

    public void resetChoices() {
        this.choice = Choice._ERR_NONE_SELECTED;
        this.proxyGetResponseList = null;
        this.proxyGetResponseRecord = null;
        this.proxySetResponseList = null;
        this.proxySetThenGetResponseList = null;
        this.proxyActionResponseList = null;
        this.proxyActionThenGetResponseList = null;
        this.proxyTransCommandResponse = null;
    }

    public String toString() {
        if (this.choice == Choice.PROXY_GET_RESPONSE_LIST) {
            if (this.proxyGetResponseList != null) {
                return "choice: {proxyGetResponseList: " + this.proxyGetResponseList + "}";
            } else {
                return "choice is proxyGetResponseList but proxyGetResponseList is null";
            }
        } else if (this.choice == Choice.PROXY_GET_RESPONSE_RECORD) {
            if (this.proxyGetResponseRecord != null) {
                return "choice: {proxyGetResponseRecord: " + this.proxyGetResponseRecord + "}";
            } else {
                return "choice is proxyGetResponseRecord but proxyGetResponseRecord is null";
            }
        } else if (this.choice == Choice.PROXY_SET_RESPONSE_LIST) {
            if (this.proxySetResponseList != null) {
                return "choice: {proxySetResponseList: " + this.proxySetResponseList + "}";
            } else {
                return "choice is proxySetResponseList but proxySetResponseList is null";
            }
        } else if (this.choice == Choice.PROXY_SET_THEN_GET_RESPONSE_LIST) {
            if (this.proxySetThenGetResponseList != null) {
                return "choice: {proxySetThenGetResponseList: " + this.proxySetThenGetResponseList + "}";
            } else {
                return "choice is proxySetThenGetResponseList but proxySetThenGetResponseList is null";
            }
        } else if (this.choice == Choice.PROXY_ACTION_RESPONSE_LIST) {
            if (this.proxyActionResponseList != null) {
                return "choice: {proxyActionResponseList: " + this.proxyActionResponseList + "}";
            } else {
                return "choice is proxyActionResponseList but proxyActionResponseList is null";
            }
        } else if (this.choice == Choice.PROXY_ACTION_THEN_GET_RESPONSE_LIST) {
            if (this.proxyActionThenGetResponseList != null) {
                return "choice: {proxyActionThenGetResponseList: " + this.proxyActionThenGetResponseList + "}";
            } else {
                return "choice is proxyActionThenGetResponseList but proxyActionThenGetResponseList is null";
            }
        } else if (this.choice == Choice.PROXY_TRANS_COMMAND_RESPONSE) {
            if (this.proxyTransCommandResponse != null) {
                return "choice: {proxyTransCommandResponse: " + this.proxyTransCommandResponse + "}";
            } else {
                return "choice is proxyTransCommandResponse but proxyTransCommandResponse is null";
            }
        } else {
            return "unknown";
        }
    }

   public enum Choice {
        _ERR_NONE_SELECTED(-1),
        PROXY_GET_RESPONSE_LIST(1),
        PROXY_GET_RESPONSE_RECORD(2),
        PROXY_SET_RESPONSE_LIST(3),
        PROXY_SET_THEN_GET_RESPONSE_LIST(4),
        PROXY_ACTION_RESPONSE_LIST(5),
        PROXY_ACTION_THEN_GET_RESPONSE_LIST(6),
        PROXY_TRANS_COMMAND_RESPONSE(7);

        private final int value;

        private Choice(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }

        public static Choice getEnumByValue(int value) {
            for (Choice item : Choice.values()) {
                if (value == item.getValue()) {
                    return item;
                }
            }
            return null;
        }
    }
}



